/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/

/*****************************************************************************/
/** \file demo_i2c.h
**
**
**
** History:
** - 
*****************************************************************************/
#ifndef __HLY_I2C_H__
#define __HLY_I2C_H__
/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include "main.h"

/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/


/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/



/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/


/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
/******************************************************************************
 ** \brief	 I2C_Config
 ** \param [in] 
 **            	
 ** \return  none
 ** \note  
 ******************************************************************************/
void I2C_Config(void);

/*****************************************************************************
 ** \brief	 At24c256_read_str
 **			 连续读取At24c256数据
 ** \param [in] addr ：起始地址
 **            	ch	 : 数据保存的容器(数组)  
**				sizevalue: 读取的数据的个数
 ** \return  0/1
 ** \note  	 例：  unsigned char  array[10];			//定义一个10字节的容器
 **	  At24c256_read_str(0x0010, Buffer, 5); //从地址0x0010开始读取5个字节的数据放到数组array中
 *****************************************************************************/
uint16_t At24c256_read_str(uint16_t addr,  uint8_t *ch, uint16_t sizevalue);
 
/*****************************************************************************
 ** \brief	 At24c256_read_byte
 **			 从At24C256中读数据
 ** \param [in]  addr : 地址
 **            	
 ** \return  返回8位数据
 ** \note   
 ****************************************************************************/
uint8_t  At24c256_read_byte(uint16_t addr);
/*****************************************************************************
 ** \brief	 At24c256_write_byte
 **			 写数据到At24C256
 ** \param [in] addr ：地址
**				ch   : 数据
 **            	
 ** \return  -1：超出地址范围 0：写完成
 ** \note  
 *****************************************************************************/ 
int16_t  At24c256_write_byte(uint16_t addr , uint8_t ch);




#define  SCL_OUT_LCD()  	GPIO_ENABLE_OUTPUT(P2TRIS, GPIO_PIN_5)

#define  SCL_IN_LCD()		GPIO_ENABLE_INPUT(P2TRIS, GPIO_PIN_5)

#define  SCL_H_LCD  	P25 = 1

#define  SCL_L_LCD  	P25 = 0

#define  SDA_OUT_LCD()  	GPIO_ENABLE_OUTPUT(P2TRIS, GPIO_PIN_6)

#define  SDA_IN_LCD()		GPIO_ENABLE_INPUT(P2TRIS, GPIO_PIN_6)

#define  SDA_H_LCD  	P26 = 1

#define  SDA_L_LCD  	P26 = 0


void Seg_san_off(void);
void Seg_san_on(void);
void  I2C_SendMasterCmd(uint8_t Cmd);
void  I2C_MasterWriteBuffer(uint8_t Data);



void LCD_I2C_Start(void);
void LCD_I2C_Stop(void);
void LCD_read_ACK(void);
void LCD_I2C_init();
void LCD_write_byte(unsigned char date);
unsigned char LCD_read_byte() ;
void LCD_write_add(unsigned char address,unsigned char date) ;
unsigned char LCD_read_add(unsigned char address,char ACK);
void LCD_send_ACK(char ACK);
void LCD_write_MultipleByte(unsigned char address,unsigned char length,unsigned char *date);
void LCD_read_MultipleByte(unsigned char *temp,unsigned char address,unsigned char data_size) ;


#endif /* __DEMO_I2C_H__ */






